#!/usr/bin/env python
# encoding: utf-8
"""
ReducerTest.py

Tests for the Reducer class.

Created by Alakazam on 2008-05-26.
Copyright (c) 2008. All rights reserved.
"""

import unittest
from Log       import Log
from Generator import Generator
from Reducer   import Reducer

class ReducerTest(unittest.TestCase):
  def setUp(self):
    # Number of points to use for testing
    self.n      = 500
    self.outDim = 3
    self.inDim  = 60
    
    generator = Generator(n=self.n, dim=self.inDim)
    generator.generateData()
    
    self.data = generator.data
    self.log = Log(verbosity=Log.QUIET)
  
  def testNotimplemented(self):
    self.assertRaises(NotImplementedError, Reducer, algorithm="NotImplemented")
  
  def testNone(self):
    reducer = Reducer(algorithm="None", data=self.data, outDim=self.outDim, log=self.log)
    
    reducer.doReduction()
    
    self.assertEqual(reducer.outData.shape, (self.n, self.outDim))
  
  def testPCA(self):
    reducer = Reducer(algorithm="PCA", data=self.data, outDim=self.outDim, log=self.log)
    
    reducer.doReduction()
    
    self.assertEqual(reducer.outData.shape, (self.n, self.outDim))
  
  def testIsomap(self):
    reducer = Reducer(algorithm="Isomap", data=self.data, outDim=self.outDim, log=self.log)
    
    reducer.doReduction()
    
    self.assertEqual(reducer.outData.shape, (self.n, self.outDim))
  
  def testDiffusionMaps(self):
    reducer = Reducer(algorithm="DiffusionMaps", data=self.data, outDim=self.outDim, log=self.log)
    
    reducer.doReduction()
    
    self.assertEqual(reducer.outData.shape, (self.n, self.outDim))
  
  def testMDS(self):
    reducer = Reducer(algorithm="MDS", data=self.data, outDim=self.outDim, log=self.log)
    
    reducer.doReduction()
    
    self.assertEqual(reducer.outData.shape, (self.n, self.outDim))

if __name__ == '__main__':
  unittest.main()
